Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Writing Private Draw Context Methods

Once you've written the public draw context methods supported by your drawing engine, you need to write several private draw context methods. In particular, you need to write a TQADrawPrivateNew method to initialize a draw context and a TQADrawPrivateDelete method to delete a draw context. The TQADrawPrivateNew method is called whenever an application creates a new draw context by calling the QADrawContextNew function. Listing 11 illustrates a sample TQADrawPrivateNew method.

Listing 11 A TQADrawPrivateNew method

TQAError MyDrawPrivateNew (
    TQADrawContext      *drawContext,
    const TQADevice     *device,
    const TQARect       *rect,
    const TQAClip       *clip,
    unsigned long       flags)
{
    MyPrivateData       *myData;

    /*Allocate a new MyPrivateData structure and store it in draw context.*/
    myData = MyDataNew(...);
    drawContext->drawPrivate = (TQADrawPrivate *) myData;
    if (!myData)
        return (kQAOutOfMemory);

    /*Set the method pointers of drawContext to point to our draw methods.*/
    newDrawContext->setFloat = MySetFloat;
    newDrawContext->setInt = MySetInt;
    ...
    return(kQANoErr);
}

As you can see, the MyDrawPrivateNew function defined in Listing 11 allocates space for its private data, installs a pointer to that data in the drawPrivate field of the draw context structure, and then installs pointers to all the public draw context methods supported by the drawing engine into the draw context structure.

Your TQADrawPrivateDelete method should simply undo any work done by your TQADrawPrivateNew method. In this case, the delete method just needs to release the private storage allocated by the TQADrawPrivateNew method. Listing 12 shows a sample TQADrawPrivateDelete method.

Listing 12 A TQADrawPrivateDelete method

void MyDrawPrivateDelete (TQADrawPrivate *drawPrivate)
{
    MyDataDelete((MyPrivateData *) drawPrivate);
}

You register your private draw context methods with QuickDraw 3D RAVE using another private method, the TQAEngineGetMethod method. See "Registering a Drawing Engine" for details.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |